var GLOBAL = {}; 
function W$(i){return document.getElementById(i)}
GLOBAL.namespace = function(str){ 
	var arr = str.split("."),o = GLOBAL; 
	for (i=(arr[0] == "GLOBAL") ? 1 : 0; i<arr.length; i++) { 
		o[arr[i]]=o[arr[i]] || {}; 
		o=o[arr[i]]; 
	} 
}
//event
GLOBAL.namespace("Event"); 
GLOBAL.Event.on = function(node,eventType,handler){ 
	node = typeof node == "string" ? document.getElementById(node) : node; 
	if(document.all){ 
		node.attachEvent("on"+eventType,callback); 
	} 
	else { 
		node.addEventListener(eventType,callback,false); 
	}
	function callback(e){
		handler.call(node,e);
	}
}

// getClassName
GLOBAL.namespace("Dom"); 
GLOBAL.Dom.getClassName = function(str,root,tag){ 
	if(root){ 
		root = typeof root == "string" ? 
		document.getElementById(root) : root; 
	} 
	else { 
		root = document.body;
	} 
	tag = tag || "*"; 
	var els = root.getElementsByTagName(tag),arr = [];  
	for(var i=0,n=els.length;i<n;i++){ 
		for(var j=0,k=els[i].className.split(" "),l=k.length;j<l;j++){ 
			if(k[j] == str){ 
				arr.push(els[i]); 
				break; 
			} 
		} 
	}
	return arr; 
}
// removeClass addClass
GLOBAL.Dom.addClass = function(node,str){ 
	if(!new RegExp("(^|\\s+)"+str).test(node.className)){ 
		node.className = node.className + " " + str; 
	}
} 
GLOBAL.Dom.removeClass = function(node,str){ 
	node.className = node.className.replace(new RegExp("(^|\\s+)"+str),""); 
}



// removeElement
function removeElement(_element){
	 var _parentElement = _element.parentNode;
	 if(_parentElement){
			_parentElement.removeChild(_element);
	 }
}

// innerText

if(document.getElementById&&!document.all){
	HTMLElement.prototype.__defineGetter__( "innerText", function(){  return this.textContent;});    //1
	HTMLElement.prototype.__defineSetter__( "innerText", function(sText){ this.textContent=sText;});    // 2
}

// input element focus
var doc = document,
    inputs = doc.getElementsByTagName('input'),
    supportPlaceholder = 'placeholder' in doc.createElement('input'),
    placeholder = function(input){
        var text = input.getAttribute('placeholder'),
            defaultValue = input.defaultValue;
        if(input.value!=text){
        	return;
        }
        input.value = text;
        input.onfocus = function(){
            if(input.value === defaultValue || input.value === text){
                this.value = '';
            }
        }
        input.onblur = function(){
            if(input.value === ''){
                this.value = text;
            }
        }
    };

if(!supportPlaceholder){
    for(var i = 0, len = inputs.length; i < len; i++){
        var input = inputs[i], text = input.getAttribute('placeholder');
        if(input.type === 'text' && text){
            placeholder(input);
        }
    }
}

// html code
function ToHtmlEnCode(str){
	var s = "";
	if (str.length == 0) return "";
	s = str.replace(/&/g, "&gt;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/ /g, "&nbsp;");
	s = s.replace(/\'/g, "'");
	s = s.replace(/\"/g, "&quot;");
	s = s.replace(/\n/g, "<br>");
	return s;
}


function ToHTMLDeCode(str){
	var s = "";
	if (str.length == 0) return "";
	s = str.replace(/&gt;/g, "&");
	s = s.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	s = s.replace(/&nbsp;/g, " ");
	s = s.replace(/'/g, "\'");
	s = s.replace(/&quot;/g, "\"");
	s = s.replace(/<br>/g, "\n");
	return s;
}


